<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>练习</title>
		<script type="text/javascript">
			function checkName(){
				var reg = /^\w{5,10}$/;
				var nameInput = document.getElementById("nameId").value;
				if(reg.test(nameInput)){
					nameId1.className = "ok";
				}else{
					nameId1.className = "error";
				}
			}
			
			function checkMail(){
				var reg = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/g;
				var mailInput = document.getElementById("mailId").value;
				if(reg.test(mailInput)){
					mailId1.className = "ok";
				}else{
					mailId1.className = "error";
				}
			}
		</script>
		<style type="text/css">
			.ok{
				color: green;
			}
			.error{
				color: red;
			}
		</style>
	</head>
	<body>
		<span>名字：</span>
		<input type="text" id="nameId" onblur="checkName()"/>
		<span id="nameId1">5-10位的数字、字母、下划线</span><br />
		<span>邮箱：</span>
		<input type="text" id="mailId" onblur="checkMail()"/>
		<span id="mailId1">必须符合邮箱的格式</span>
	</body>
</html>
